<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
	<title>敏感词过滤</title>
	<style type="text/css">
	* {
		padding: 0;
		margin: 0;
	}
    </style>
</head>
<body>
	<div class="container">
		<h1>敏感词过滤</h1>
		<textarea id="txt1" rows="10" cols="40">
			我在北京的百度总部上班，然后我在上班期间打开淘宝进行购物，被公司发现开除了
		</textarea><br>
		<input id="btn1" type="button" value="过滤" /><br>
		<textarea id="txt2" rows="10" cols="40">	
		</textarea>
	</div>
	<script src="https://cdn.staticfile.org/jquery/3.2.0/jquery.js"></script>
	<script type="text/javascript">
	window.onload=function ()
	{
		var oTxt1=document.getElementById('txt1');
		var oTxt2=document.getElementById('txt2');
		var oBtn=document.getElementById('btn1');
		
		oBtn.onclick=function ()
		{
			var re=/北京|百度|淘宝/g;
			console.log(oTxt1.value)
			console.log(oTxt1.innerHTML)
			
			// oTxt2.value=oTxt1.value.replace(re, '***');
			oTxt2.innerHTML = oTxt1.innerHTML.replace(re, '***')
		};
	};
	</script>
</body>
</html>